﻿var _emailFormat = /[\w-\.]+@([\w-]+\.)+[\w-]{2,4}/;
var _emailFormatError = "Invalid Email Address";

var _ssnFormat = /\d{3}-\d{2}-\d{4}/;
var _ssnFormatError = "Invalid SSN";

var _urlFormat = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/;
var _urlFormatError = "Invalid Url";

var _userNameFormat = /[a-zA-Z0-9]{7,20}/;
var _userNameFormatError = "Username should be alphanumeric and between 7 to 20 character";

// minimum 7 and maximum 20 alphanumeric character
var _passwordFormat = /(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})/;
var _passwordFormatError = "Password is invalid";

var _usPhoneNumberFormat = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/;
var _usPhoneNumberFormatError = "Invalid Phone Number";

var _textOnlyFormat = /[\s\w\d@.,&#-\/:]+/;
var _textOnlyFormatError = "Only text is allowed";

var _numberOnlyFormat = /[\d]+/;
var _numberOnlyFormatError = "Only number is allowed";

var _domainNameFormat = /([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/;
var _domainNameFormatError = "Invalid domain name";

var _addressFormat = /[\s\w\d@.,&#-\/:]+/;
var _addressFormatError = "Address has some restricted word or letter";

//// Origianl expression(Modified with escapes): </?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)/?>
//var _htmlTagFormat = /</?\\w+((\\s+\\w+(\\s*=\\s*(?:\".*?\"|'.*?'|[^'\">\\s]+))?)+\\s*|\\s*)/?>/;
//var _htmlTagFormatError = "Invalid Html tag";
function IsSSN(text)
{
    return IsValid(text, _ssnFormat);
}
        
function IsUserName(text)
{
    return IsValid(text, _userNameFormat);
}

function IsPassword(text)
{
    return IsValid(text, _passwordFormat);
}

function IsUrl(text)
{
    return IsValid(text, _urlFormat);
}

function IsEmail(text)
{
    return IsValid(text, _emailFormat);
}

function IsNumber(text)
{
    return IsValid(text, _numberOnlyFormat);
}

function IsDomainName(text)
{
    return IsValid(text, _domainNameFormat);
}

function IsPlainText(text)
{
    return IsValid(text, _textOnlyFormat);
}

function IsAddress(text)
{
    return IsValid(text, _addressFormat);
}

function IsValid(text, expression)
{
    var regex = new RegExp(expression);
    if (text.match(regex))
    {
        return true;
    }
    else
    {
        return false;
    }
}